﻿using System;
using System.Diagnostics;
using System.IO;
using Microsoft.Office.Interop.Excel;

namespace HmLab.Func1;

internal class LbCleanFunc1Out {

  /// <summary>
  /// <see cref="Haimen.Func1.Func1OutCleaner"/>
  /// </summary>
  public void Run() {
    Console.WriteLine("----LbCleanFunc1OutLbCleanFunc1Out");

    string tplPath = @"E:\work_etc\nina\2023haimen2\workshop_cslab\输Q出\数据源gen.xlsx";
    string mergeOut = @"E:\work_etc\nina\2023haimen2\workshop_cslab\输Q出\数据源gen_del.xlsx";
    File.Copy(tplPath, mergeOut, overwrite: true);

    Application excelApp = new() {
      Visible = true, // 隐藏会导致退出失败时残留一堆不可见进程
      ScreenUpdating = false,
    };

    // 验证关闭后紧接着删除会不会有占用问题
    _ = excelApp.Workbooks.Open(mergeOut);
    excelApp.Quit();

    Debug.Assert(File.Exists(mergeOut));
    File.Delete(mergeOut);
  }
}
